<template>
    <div class="share-container">
        <img style="width: 100%;" src="/images/weixin2/invest.jpg" />
        <div class="title">分享流程</div>
        <div class="prompt">
            1、点击右上方的菜单，选择 "发送给朋友" 、 "分享到朋友圈" ；<br/>
            2、选择需要发送的微信好友、直接分享到微信朋友圈 ；<br/>
            3、点击 "发送" 按钮，即可分享成功。<br/>
        </div>
        <div style="padding-top: 20px;"></div>
        <van-cell-group>
            <van-cell title="邀请记录" is-link to="sharerecord" />
        </van-cell-group>
        <!--<van-button type="default" v-if="isDev" @click="isDev&&goWithVar">测试带参跳转</van-button>-->
    </div>
</template>

<script>
    import wx from 'weixin-js-sdk'
    import Vue from 'vue'
    import {mapState} from 'vuex'
    import {Button} from 'vant'
    import {isDev} from "@/utils/tools";
    Vue.use(Button);
    export default {
        name: "Share",
        data(){
            return{
                isDev:isDev,
                title:'国际体育文化演艺中心-注册有礼',
                desc:'国际体育文化演艺中心-注册有礼',
                imgUrl:'http://guijiwenhua.oss-cn-hangzhou.aliyuncs.com/20190111/802ba962a129494693696786092565e4.jpg'

            }
        },
        created(){

        },
        mounted(){
            let _this = this
            wx.ready(function () {
                _this.updateAppMessageShareData()
                _this.updateTimelineShareData()
            })
        },
        computed:{
            ...mapState({
                userInfo:state=> state.user.userInfo,
            })
        },
        methods:{
            updateAppMessageShareData(){
                let _this =this
                let url = window.location.href.split('#')[0]+'?share_mobile=' + this.userInfo.mobile;
                wx.updateAppMessageShareData({
                    title: _this.title, // 分享标题
                    desc: _this.desc, // 分享描述
                    link: url, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                    imgUrl: _this.imgUrl, // 分享图标
                    success: function (res) {

                    },
                    fail: function (res) {
                        // alert(JSON.stringify(res));
                        console.log(res)
                    }
                });
            },
            updateTimelineShareData(){
                let _this =this
                let url = window.location.href.split('#')[0]+'?share_mobile=' + (this.userInfo.mobile||'');
                wx.updateTimelineShareData({
                    title: _this.title, // 分享标题
                    link: url, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                    imgUrl: _this.imgUrl, // 分享图标
                    success: function (res) {
                    },
                    fail: function (res) {
                        alert(JSON.stringify(res));
                    }
                });
            },
            goWithVar(){
                let url = window.location.href.split('#')[0]+'?share_mobile=' + (this.userInfo.mobile||'');
                window.location.href=url
            }
        }
    }
</script>

<style scoped>
    .share-container {
        background-color: #f3f3f3;
        min-height: 100%;
        .title {
            color: #2C2C2C;
            font-size: 18px;
            padding: 0 10px 10px 20px;
        }
        .prompt {
            background-color: #FFFFFF;
            padding: 10px 15px;
            font-size: 13px;
            color: #475057;
            line-height: 25px;
        }
    }
</style>
